package newhiant.hianto2o.com.activity;

import android.databinding.DataBindingUtil;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import newhiant.hianto2o.com.BR;
import newhiant.hianto2o.com.R;
import newhiant.hianto2o.com.adapter.CommonAdapter;
import newhiant.hianto2o.com.databinding.ActivityAdapterBinding;
import newhiant.hianto2o.com.model.User;

public class AdapterActivity extends AppCompatActivity {
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityAdapterBinding mActivityAdapterBinding = DataBindingUtil.setContentView(this, R.layout.activity_adapter);

        List<User> mlist = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            // 3个网络图片1个本地图片，依次循环
            User user = new User(i, "user" + i, (i % 2 == 0 ? "男" : "女"), (i & 0x03) < 3 ? "http://upload-images.jianshu.io/upload_images/966283-d2985f45c0c1e618.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/500" : null);
            mlist.add(user);
        }
// 创建Adapter。BR类似与R文件，用于存储变量名称。位置也与R一样，在app包名下
        CommonAdapter adapter = new CommonAdapter(this, mlist, R.layout.item_adapter, BR.user);
        mActivityAdapterBinding.setCommonAdapter(adapter);
    }
}
